
	<!-- row -->

	<div class="row" style="overflow-y: hidden;height:100%;padding-bottom:10px;">

		<!-- a blank row to get started -->
		<div class="col-lg-3 col-md-4 col-sm-5" style="height: 100%;">
			<div style="height: 100%;background-color:#fff;">
				<select class="form-control input-sm lineSearch col-12"></select>
				<div>
					<a href="ajax/modal-content/modal-editLineInfo.html" data-toggle="modal" data-target="#editLineInfoModal"  rel="tooltip" data-placement="top" data-original-title="点击修改信息">
						<p id="lineInfoSpan" style="margin:5px;color:#333;background-color:fcfcfc">点击上方搜索框搜索线路</p>
					</a>
				</div>
				<div id="stationsDiv" >
					<ul class="mui-table-view sortable" id="stationUl"></ul>
				</div>
				<div style="padding:5px 5px 10px 5px;background-color:#eee">
					<div class="smart-form">
						<label class="toggle">
							<input type="checkbox" id="dragSortButton">
							<i data-swchon-text="开" data-swchoff-text="关"></i>拖动站点排序
						</label>
					</div>
					<div style="padding:4px 3px">
						<a href="ajax/modal-content/modal-addStation.html" data-toggle="modal" data-target="#addStationModal" class="btn btn-labeled btn-warning" id="addStationBtn"> 
							<span class="btn-label"><i class="fa fa-plus"></i></span>添加站点 
						</a>
						<a class="btn btn-labeled btn-success pull-right" id="submitAll"> 
							<span class="btn-label"><i class="fa fa-save"></i></span>保存修改 
						</a>
					</div>
				</div>

			</div>

		</div>
		<form class="smart-form" style="z-index:10;width:150px;float:right;right:0px;position:fixed" id="showBusesDiv">
			<fieldset style="padding: 8px 14px;background: rgba(255,255,255,0);">
				<section>
					<label class="toggle">
						<input type="checkbox" name="checkbox-toggle" checked="checked" id="showBuses">
						<i data-swchon-text="ON" data-swchoff-text="OFF"></i>实时车辆</label>
				</section>
			</fieldset>
		</form>
		<div class="row col-lg-9 col-md-8 col-sm-7" style="height: 100%;"  id="map_main">
		</div>
			
	</div>

	<!-- end row -->
	<!-- Dynamic Modal -->  
	<div class="modal fade" id="addStationModal" role="dialog" aria-labelledby="addStationModal" aria-hidden="true">  
		<div class="modal-dialog">  
			<div class="modal-content">
				<!-- content will be filled here from "ajax/modal-content/modal-addStation.html" -->
			</div>  
		</div>  
	</div>  
	<!-- /.modal --> 

	<!--模态框（Modal） -->
	<div class="modal fade" id="editLineInfoModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
		<div class="modal-content">
			<!-- content will be filled here from "ajax/modal-content/modal-editLineInfo.html" -->
		</div>
		</div>
	</div>
	<!-- /.modal --> 


<script type="text/javascript">
	var lType=['下行普通','上行普通','下行循环','上行循环','内环线','外环线','单环线'];
	var lDiscountType=['无折扣','济南公交标准折扣','济南公交9折折扣','好运巴士标准折扣'];
	var lBusDataSource=['无实时数据','济南微步','济南车来了'];
	var lineInfoSameKeys = ['lName','lKeyWord','lBusDataSource','lPriceText','lPriceArr','lDiscountType','lCompany','lServicePhone','lTag'];
	var lineInfoKeys = ['lName','lKeyWord','lBusDataSource','lPriceText','lPriceArr','lDiscountType','lCompany','lServicePhone','lTag','lStartName','lEndName','lType','lBusDataSourceID','lBackLine','lForder','lTimeTable'];
	var lid = 0;
	var lineInfo = null;
	var map_main =null;
	var map_addStation = null;
	var searchTime = 0;
	var tempStations=null;
	var nowEditPolyline = null;
	var trafficTimer = null;
	$('body').append($('#addStationModal'));
	//$('body').append($('#newStationModal'));
	$('body').append($('#editLineInfoModal'));
	
	
		
	$(window).resize(function() {
		setTimeout(function(){
			$('#stationsDiv').height($(window).height() - 128 - $("#stationsDiv").offset().top);
		},50);		
		if(Date.parse(new Date())-searchTime >10000){
			$(".lineSearch").select2({
				ajax: {
					dataType: 'json',
					delay:250,
					url: function(){
						searchTime = Date.parse(new Date());
						return "//api.waitbus.com/v3/?mothed=getLinesBylNames&lid=" + lid + "&token=" + token; 
					},
					processResults: function (data, params) {
						params.page = 1;
						var itemList = [];
						if(data.status.code==0){
							var arr = data.result;
							for(var item = 0; item<arr.length;item++){
								 itemList.push({id: arr[item].lID, text:arr[item].lName + " " + arr[item].lStartName + " - " + arr[item].lEndName})
							}
						}else{
							if(data.status.code!=-7)alert(data.status.msg);
						}
						return {results: itemList,pagination: {more: false}};
					},
				},
				placeholder:'请搜索线路',//默认文字提示
			});
		}
		if($(window).width()>749){
			if(map_main == null){
				$("#showBuses").click(function () {
					reloadTraffic();
				});
				map_main = new BMap.Map("map_main",{enableMapClick:false});
				map_main.centerAndZoom("济南");
				map_main.setCurrentCity("济南");        //由于有3D图，需要设置城市哦
				map_main.enableScrollWheelZoom();
				map_main.disableDoubleClickZoom()
				var mapType2 = new BMap.MapTypeControl({anchor: BMAP_ANCHOR_TOP_LEFT});
				map_main.addControl(mapType2);          //左上角，默认地图控件
				var ctrl = new BMapLib.TrafficControl({
				   showPanel: false //是否显示路况提示面板
				});  
				map_main.addControl(ctrl);
				ctrl.setAnchor(BMAP_ANCHOR_BOTTOM_RIGHT);  
				map_main.setMapStyle({styleJson:[{"featureType": "poilabel","elementType": "labels","stylers": {"visibility": "off"}}]});
			}
		}else{
			$("#showBusesDiv").hide();
		}
	});
	$('#dragSortButton').change(function(){
		$(".sortable" ).sortable({disabled:!$('#dragSortButton')[0].checked});
	});
	$(".sortable" ).sortable({ 
		cursor: "move", 
		axis: 'y',
		disabled:true,
		items :"li", //只是li可以拖动 
		opacity: 0.6, //拖动时，透明度为0.6 
		revert: false, //释放时，增加动画 
		update : function(event, ui){ //更新排序之后 
			ids = $(this).sortable("toArray"); 
			var newlStation = [];
			for(var i =0 ;i<ids.length;i++){
				newlStation.push(lineInfo.lStation[parseInt(ids[i].substr(12))]);
			}
			lineInfo.lStation = newlStation;
			reloadLine();
		} 
		
	});

	$(".lineSearch").on("select2:select",function(e){
		searchTime = 0;
	　　lid = e.params.data.id
		$.getJSON("//api.waitbus.com/v3/?mothed=getLineInfoWithLinesBylID&lid=" + lid + "&token=" + token,function(data){
			if(data.result){
				lineInfo = data.result;
				reloadLine();
			}
		});
	});

	$('#editLineInfoModal').on('shown.bs.modal', function () {
		$('#editLineInfoModal h4').text("修改线路信息 - ID:" +lid);
		$("#editLineInfoModallType").empty();
		$("#editLineInfoModallDiscountType").empty();
		$("#editLineInfoModallBusDataSource").empty();
		for(var i=0;i<lType.length;i++){
			$("#editLineInfoModallType").append("<option value='" + i + "'>" + lType[i] + "</option>"); 
		}
		for(i=0;i<lDiscountType.length;i++){
			$("#editLineInfoModallDiscountType").append("<option value='" + i + "'>" + lDiscountType[i] + "</option>"); 
		}
		for(i=0;i<lBusDataSource.length;i++){
			$("#editLineInfoModallBusDataSource").append("<option value='" + i + "'>" + lBusDataSource[i] + "</option>"); 
		}
		for(i=0;i<lineInfoKeys.length;i++){
			$('#editLineInfoModal' + lineInfoKeys[i]).val(lineInfo[lineInfoKeys[i]]);
		}
		$("#editLineInfoModalSubmit").click(function(e){
			for(var i=0;i<lineInfoKeys.length;i++){
				lineInfo[lineInfoKeys[i]] = $('#editLineInfoModal'+ lineInfoKeys[i]).val();
			}
			if($('#editLineInfoModalAutoSaveBack')[0].checked && lineInfo.lType<6){
				if(lineInfo.lType%2 == 0){
					var backLineType = lineInfo.lType - -1;
					var backLineForder = lineInfo.lForder - -1;
				}else{
					var backLineType = lineInfo.lType - 1
					var backLineForder = lineInfo.lForder - 1
				}
				var backLineInfo = {
					lStartName:lineInfo.lEndName,
					lEndName:lineInfo.lStartName,
					lType:backLineType,
					lBackLine:lid,
					lForder:backLineForder
				};
				console.log(backLineInfo);
				for(i=0;i<lineInfoSameKeys.length;i++){
					backLineInfo[lineInfoSameKeys[i]] = lineInfo[lineInfoSameKeys[i]];
				}
				postLineInfo(lineInfo.lBackLine,backLineInfo);	
			}
			postLineInfo(lid,lineInfo);
		});
	});
	$("#submitAll").click(function(){
		postLineInfo(lid,lineInfo);
	});
	  
	$('#addStationModal').on('shown.bs.modal', function () {
		$(".modallineSearch").select2({
			ajax: {
				dataType: 'json',
				delay:250,
				url: function(){
					searchTime = Date.parse(new Date());
					return "//api.waitbus.com/v3/?mothed=getLinesBylNames&lid=" + lid + "&token=" + token; 
				},
				processResults: function (data, params) {
					params.page = 1;
					var itemList = [];
					if(data.status.code==0){
						var arr = data.result;
						for(var item = 0; item<arr.length;item++){
							 itemList.push({id: arr[item].lID, text:arr[item].lName + " " + arr[item].lStartName + " - " + arr[item].lEndName})
						}
					}else{
						if(data.status.code!=-7)alert(data.status.msg);
					}
					return {results: itemList,pagination: {more: false}};
				},
			},
			placeholder:'请搜索线路',//默认文字提示
		});	
		$(".modallineSearch").on("select2:select",function(e){
			$.getJSON("//api.waitbus.com/v3/?mothed=getLineInfoBylID&lid=" + e.params.data.id + "&token=" + token,function(data){
				if(data.result){
					tempStations=data.result.lStation;
					$("#addStationTable").empty();
					for(var i=0;i<data.result.lStation.length;i++){
						$("#addStationTable").append("<option value='" + i + "'>" + data.result.lStation[i].sName + (data.result.lStation[i].sCompass ==''?'':' - ' + data.result.lStation[i].sCompass) + ' ('  + data.result.lStation[i].sRoad + ")</option>"); 
					}
				}
			});
		});
			
		$('#copyStationBtn').click(function () {
			var arr = $("#addStationTable").val();
			if(tempStations!=null && lineInfo!=null && arr !=null ){
				var j = Math.min(parseInt($('#copyStationNum').val()),lineInfo.lStation.length);
				for(var i = 0; i < arr.length; i++){
					lineInfo.lStation.insert(j,tempStations[arr[i]]);
					j++;
				}
				reloadLine();
				$.smallBox({
					title : "站点已复制",
					content : "<i class='fa fa-clock-o'></i> <i>点击保存会上传至服务器，否则不会真正复制</i>",
					color : "#659265",
					iconSmall : "fa fa-check fa-2x fadeInRight animated",
					timeout : 5000
				});
				$('#copyStationNum').val(j);
			}else{
				$.bigBox({
					title : "线路未选择或站点未选择！",
					content : "在添加站点之前，请先确认已经搜索过线路同时您已经点击下拉框中所列出的站点",
					color : "#C79121",
					timeout: 8000,
					icon : "fa fa-times fadeInLeft animated",
				}); 
			}
			
		});
		$('#searchStation').on('shown.bs.tab', function () {
			$(".stationSearch").select2({
				ajax: {
					dataType: 'json',
					delay:250,
					url: function(){
						searchTime = Date.parse(new Date());
						return "//api.waitbus.com/v3/?mothed=getStationsByName" + "&token=" + token; 
					},
					processResults: function (data, params) {
						params.page = 1;
						var itemList = [];
						if(data.status.code==0){
							var arr = data.result;
							for(var item = 0; item<arr.length;item++){
								 itemList.push({id: arr[item].sID, text:arr[item].sName + (arr[item].sCompass ==''?'':' - ' + arr[item].sCompass) + ' ('  + arr[item].sRoad + ')'})
							}
						}else{
							alert(data.status.msg);
						}
						return {results: itemList,pagination: {more: false}};
					},
				},
				placeholder:'请输入汉字、拼音或首字母',//默认文字提示
				minimumInputLength: 2,
			});
		});
		$(".stationSearch").on("select2:select",function(e){
			s = e.params.data.id
			$.getJSON("//api.waitbus.com/v3/?mothed=getStationsWithLinesBysIDs&s=" + s + "&token=" + token,function(data){
				$('#insertSingleStation').removeAttr("disabled");
				var res = data.result[0];
				$('#addStationModaltationPic')[0].src = 'http://restapi.amap.com/v3/staticmap?zoom=16&size=331*320&markers=,,:' + (res.sLng+.00591823) + ',' + (res.sLat+31088e-8) + '&key=e8985788ebcc94a2d16bc4d813c072eb';
				var html = '';
				for(var j =0;j<res.busline.length;j++){
					html += '<li class="mui-table-view-cell mui-ellipsis">' + res.busline[j].lName + '<span class="text-muted"> ' + '→' + res.busline[j].lEndName + '</span></li>';
				}
				$('#addStationModaltationInfo').html(html);
				tempStations = data.result;
			});
		});
		$('#insertSingleStation').click(function(){
			if(tempStations!=null && lineInfo!=null){
				lineInfo.lStation.insert(Math.min(parseInt($('#insertSingleStationNum').val()),lineInfo.lStation.length),tempStations[0]);
				reloadLine();
			}else{
				$.bigBox({
					title : "线路未选择或站点未选择！",
					content : "在添加站点之前，请先确认已经搜索过线路同时您已经点击下拉框中所列出的站点",
					color : "#C79121",
					timeout: 8000,
					icon : "fa fa-times fadeInLeft animated",
				});
			}
		});
		$('#newStation').on('shown.bs.tab', function () {
			if(map_addStation == null){
				if($(window).width()<700)$('#map_addStation').height("150");
				map_addStation = new BMap.Map("map_addStation",{enableMapClick:false});
				map_addStation.setCurrentCity("济南");
				map_addStation.centerAndZoom("济南");
				map_addStation.enableScrollWheelZoom();
				var mapType2 = new BMap.MapTypeControl({anchor: BMAP_ANCHOR_TOP_LEFT});
				map_addStation.addControl(mapType2);   
				
				map_addStation.addEventListener("click", function(e){
					var lng_lat = (e.point.lng - 0.012316) + ',' + (e.point.lat - 0.006531);
					$("#addStationLoc").val(lng_lat); 
					var point = new BMap.Point(e.point.lng,e.point.lat);    
					var marker = new BMap.Marker(point);
					map_addStation.clearOverlays();
					map_addStation.addOverlay(marker);
				});
				
				$('#addStationName').on('input', function (){
					var value = $('#addStationName').val();
					var result = pinyinUtil.getPinyin(value, ' ', false, false);
					$("#addStationPinyin").val(result);
				});
				
				$('#addNewStationBtn').click(function (){
					if(lineInfo==null){
						$.bigBox({
							title : "线路未选择！",
							content : "在添加站点之前，请先确认已经搜索了线路",
							color : "#C79121",
							timeout: 8000,
							icon : "fa fa-times fadeInLeft animated",
						});
						return;
					}
					var staInfo = {};
					var lng_lat = $('#addStationLoc').val();
					var pinyin = $('#addStationPinyin').val();
					var szm = '';
					var arrpinyin = pinyin.split(' ');
					for(var i=0;i<arrpinyin.length;i++){
						if(arrpinyin[i].length>0){
							szm+=arrpinyin[i][0];
						}else{
							$.bigBox({
								title : "出现错误",
								content : '系统在处理拼音时遇到了错误，请检查拼音是否为空或空格又连续出现的情况',
								color : "#C79121",
								timeout: 8000,
								icon : "fa fa-times fadeInLeft animated",
							});	
							return;
						}
					}
					pinyin=pinyin.replace(/\s+/g, "");
					staInfo['sTag']=$('#addStationTag').val();
					staInfo['sRoad']=$('#addStationRoad').val();
					staInfo['sCompass']=$('#addStationCompass').val();
					staInfo['sName']=$('#addStationName').val();
					staInfo['sLng']=parseFloat(lng_lat.split(",")[0]);
					staInfo['sLat']=parseFloat(lng_lat.split(",")[1]);
					staInfo['sPinyin']=pinyin;
					staInfo['sSzm']=szm;
					if(staInfo['sLng']+staInfo['sLat']<100){
						$.bigBox({
							title : "出现错误",
							content : '请点击地图添加经纬度',
							color : "#C79121",
							timeout: 8000,
							icon : "fa fa-times fadeInLeft animated",
						});	
						return;
					}
					if(staInfo['sPinyin']==""||staInfo['sSzm']==""||staInfo['sName']==""||staInfo['sRoad']==""){
						$.bigBox({
							title : "出现错误",
							content : '除备注外，其他字段不允许空',
							color : "#C79121",
							timeout: 8000,
							icon : "fa fa-times fadeInLeft animated",
						});	
						return;
					}
					$.post('//api.waitbus.com/v3/?mothed=createNewStation' + "&token=" + token,staInfo,function(data){
						res = JSON.parse(data);
						if(res.status.code==0){
							lineInfo.lStation.insert(lineInfo.lStation.length,res.result[0]);
							reloadLine();
							$.bigBox({
								title : "插入成功",
								content : "您提交的站点数据均已提交成功,站点插入到了尾站处，请拖动更改位置",
								color : "#739E73",
								timeout: 8000,
								icon : "fa fa-check",
							});
							$('#addStationModal').modal('hide');
						}else{
							$.bigBox({
								title : "出现错误",
								content : res.status.msg + " [" + res.status.code + "]",
								color : "#C79121",
								timeout: 8000,
								icon : "fa fa-times fadeInLeft animated",
							});
						}
					});
				});
				
				$('#addStationName').blur(function (){
					var value = $('#addStationName').val();
					var options = {
						onSearchComplete: function(results){
							// 判断状态是否正确
							if (local.getStatus() == BMAP_STATUS_SUCCESS){
								if(results.getCurrentNumPois()>=1){
									console.log(results.getPoi(0));
									map_addStation.centerAndZoom(new BMap.Point(results.getPoi(0).point.lng,results.getPoi(0).point.lat),18);
								}	
							}
						}
					};
					var local = new BMap.LocalSearch(map_addStation, options);
					local.search(value + " 公交车站");
				});
			}
		});
	});
	
	$('#addStationModal').on('hidden.bs.modal', function () {
		map_addStation = null;
		tempStations =null;
	});
	
	//获取覆盖物位置
	function enableEditing(e){
		console.log(e);
		if(nowEditPolyline!=null){
			var allOverLays = map_main.getOverlays();
			for(var i = 2;i<allOverLays.length;i+=2){
				if(allOverLays[i]==nowEditPolyline){
					break;
				}
			}
			if(i<allOverLays.length){
				var points = []
				for(var j = 1;j<allOverLays[i].ia.length-1;j++){
					var lng = allOverLays[i].ia[j].lng-0.012316;
					var lat = allOverLays[i].ia[j].lat-0.006531;
					points.push(lng.toFixed(6) + ',' + lat.toFixed(6)); 
				}
				i=i/2;
				$.post('//api.waitbus.com/v3/?mothed=setPolyline' + "&token=" + token,{start:lineInfo.lStation[i-1].sID,end:lineInfo.lStation[i].sID,points:points.join("|")},function(data){
					res = JSON.parse(data);
					if(res.status.code==0){
						$.bigBox({
							title : "插入成功",
							content : "折线已经上传到服务器",
							color : "#739E73",
							timeout: 8000,
							icon : "fa fa-check",
						});
					}else{
						$.bigBox({
							title : "出现错误",
							content : res.status.msg + " [" + res.status.code + "]",
							color : "#C79121",
							timeout: 8000,
							icon : "fa fa-times fadeInLeft animated",
						});
					}
				});
			}
			nowEditPolyline.disableEditing();
		}
		if(e.target!=nowEditPolyline){
			nowEditPolyline = e.target;
			nowEditPolyline.enableEditing();
		}else{
			nowEditPolyline = null;
		}
	}
	function reloadTraffic(){
		$.getJSON("//api.waitbus.com/v3/?mothed=getBusWithTrafficBylID&lid=" + lid + "&token=" + token,function(data){
			if(data.status.code==0){
				var point = null;
				var marker = null;
				var label = null;
				var busIcon = new BMap.Icon("https://www.waitbus.com/img/busLocIcon.png", new BMap.Size(20,24),{anchor:new BMap.Size(10,24)});
				var busIconAir = new BMap.Icon("https://www.waitbus.com/img/busLocIconAir.png", new BMap.Size(20,24),{anchor:new BMap.Size(10,24)});
				var allOverLays = map_main.getOverlays();
				for(var i = 0;i<data.result.traffic.length;i++){
					var color = '';
					if(data.result.traffic[i].pVelocity<0||data.result.traffic[i].pVelocity>=8){
						color ="#4FD17D";
					}else if(data.result.traffic[i].pVelocity>3&&data.result.traffic[i].pVelocity<8){
						color ="#F6C64D";
					}else{
						color = "#E80D0D";
					}
					allOverLays[(i+1)*2].setStrokeColor(color);
				}
				for(var i = data.result.traffic.length*2+1;i<allOverLays.length;i++){
					map_main.removeOverlay(allOverLays[i]);
				}
				if($('#showBuses')[0].checked){
					for(var i=0;i<data.result.buses.length;i++){
						point = new BMap.Point(data.result.buses[i].bLng + 0.012316,data.result.buses[i].bLat + 0.006531);
						marker = new BMap.Marker(point,{icon:(data.result.buses[i].bName.slice(0,1)=="K"?busIconAir:busIcon)});
						map_main.addOverlay(marker);
						if(!isIE()){
							label = new BMap.Label(data.result.buses[i].bName,{offset:new BMap.Size(-1.5*data.result.buses[i].bName.length,20)});
							label.setStyle({color : "#0192cb",fontSize : "6px",backgroundColor :"0.05",border :"0",textShadow:"1px 1px 1px #fff"});
							marker.setLabel(label);
						}
						marker.addEventListener("click",function(e){
							console.log(e);
							//showStationInfoWindowByPoint(e.target.point);
						});
					}
				}
			}else{
				$.bigBox({
					title : "出现错误",
					content : data.status.msg + " [" + data.status.code + "]",
					color : "#C79121",
					timeout: 8000,
					icon : "fa fa-times fadeInLeft animated",
				});
			}
		});
		
	}

	function reloadLine(){
		var stationUlHtml = "";
		var points = [];
		var point = null;
		var marker = null;
		var label = null;
		var myIcon = new BMap.Icon("https://www.waitbus.com/img/stop_icon.png", new BMap.Size(11,11));
		$("#lineInfoSpan").html('ID:' + lid + '  '
			+ '类型:' + lType[lineInfo.lType] + '  '
			+ '数据源:' + lBusDataSource[lineInfo.lBusDataSource] + '[' + lineInfo.lBusDataSourceID + ']<br>'
			+ '发车时间:' + lineInfo.lTimeTable + '<br>'
			+ '票价:' + lineInfo.lPriceText + '[' + lDiscountType[lineInfo.lDiscountType] + ']<br>'
			+ '车队:'+lineInfo.lCompany + '[' + lineInfo.lServicePhone + ']' + '<br>'
			+ lineInfo.lTag
		);
		for(var i=0;i<lineInfo.lStation.length;i++){
			stationUlHtml += '<li class="mui-table-view-cell mui-media" id="busStationli' + i + '"><a href="javascript:;"><div class="mui-media-body">'
				+ (i+1) + '. ' + lineInfo.lStation[i].sName +(lineInfo.lStation[i].sCompass ==''?'':'<span class="text-muted"> - ' + lineInfo.lStation[i].sCompass + ' </span>')
				+'<p class="mui-ellipsis-2 pull-right">' + lineInfo.lStation[i].sTag + '</p>'
				+'<p class="mui-ellipsis text-muted">'+ lineInfo.lStation[i].sRoad + '</p>';
				+ '</div></a></li>';
		}
		$("#stationUl").html(stationUlHtml);
		$(window).resize();
		if(map_main!=null){
			map_main.clearOverlays();
			for(var i=0;i<lineInfo.lStation.length;i++){
				point = new BMap.Point(lineInfo.lStation[i].sLng + 0.012316,lineInfo.lStation[i].sLat + 0.006531);
				marker = new BMap.Marker(point,{icon:myIcon});
				map_main.addOverlay(marker);
				if(!isIE()){
					label = new BMap.Label(lineInfo.lStation[i].sName,{offset:new BMap.Size(10,-5)});
					label.setStyle({color : "#fafafa",fontSize : "8px",backgroundColor :"0.05",border :"0",textShadow:"2px 2px 2px #333"});
					marker.setLabel(label);
				}
				marker.addEventListener("click",function(e){
					console.log(e);
					showStationInfoWindowByPoint(e.target.point);
				});

				if(i>0){
					var polylinepoints = points.slice(-1);
					var polylinestring = lineInfo.lStation[i].polyline.pPoints + "";
					
					tmp = polylinestring.split("|");
					for(var j =0;j<tmp.length;j++){
						var temp = tmp[j].split(",");
						console.log(temp);
						if(temp.length==2){
							polylinepoints.push(new BMap.Point(parseFloat(temp[0]) + 0.012316,parseFloat(temp[1]) + 0.006531));
						}
					}
					polylinepoints.push(point);
					var color = '';
					if(lineInfo.lStation[i].polyline.pVelocity<0||lineInfo.lStation[i].polyline.pVelocity>=8){
						color ="#4FD17D";
					}else if(lineInfo.lStation[i].polyline.pVelocity>3&&lineInfo.lStation[i].polyline.pVelocity<8){
						color ="#F6C64D";
					}else{
						color = "#E80D0D";
					}
					var polyline = new BMap.Polyline(polylinepoints, {strokeColor:color,strokeWeight:6,strokeOpacity:0.9}); 
					map_main.addOverlay(polyline);
					polyline.addEventListener("dblclick",enableEditing);
				}
				points.push(point);
			}
			map_main.setViewport(points);
			if(trafficTimer !=null){
				clearInterval(trafficTimer);
			}
			if(lineInfo.lBusDataSource>0){
				trafficTimer = setInterval(reloadTraffic,20000);
				reloadTraffic();
			}
		}
		$("#stationsDiv li" ).on('dblclick', function(e){
			var strID =e.currentTarget.id;
			strID=parseInt(strID.substr(12));
			tempStations = strID;
			$.SmartMessageBox({
				title : '确定删除站点:['  + lineInfo.lStation[strID].sName + ']吗?',
				content : "删除站点后不会删除站点本身和相应信息，仅仅是该线路不再包含此站点",
				buttons : '[确认删除][点错了]'
			}, function(ButtonPressed) {
				if (ButtonPressed === "确认删除") {
					lineInfo.lStation.splice(tempStations,1);
					reloadLine();
					$.smallBox({
						title : "站点已删除",
						content : "<i class='fa fa-clock-o'></i> <i>点击保存会上传至服务器，否则不会真正修改</i>",
						color : "#659265",
						iconSmall : "fa fa-check fa-2x fadeInRight animated",
						timeout : 5000
					});
				}
				tempStations = null;
			});
			
		});
		$("#stationsDiv li" ).on('click', function(e){
			var strID =e.currentTarget.id;
			i=parseInt(strID.substr(12));
			if(map_main!=null){
				showStationInfoWindowBysID(i)
				map_main.centerAndZoom(new BMap.Point(lineInfo.lStation[i].sLng + 0.012316,lineInfo.lStation[i].sLat + 0.006531),19);
			}
		});
	}

	function showStationInfoWindowByPoint(point){
		for(i=0;i<lineInfo.lStation.length;i++){
			if(point.lat==lineInfo.lStation[i].sLat +0.006531 && point.lng==lineInfo.lStation[i].sLng + 0.012316){
				showStationInfoWindowBysID(i);
			}
		}
	}
	
	function showStationInfoWindowBysID(i){
		var content ='';
		for(var j = 0;j< lineInfo.lStation[i].busline.length;j++){
			if(lineInfo.lStation[i].busline[j].lID!=lid){
				content += lineInfo.lStation[i].busline[j].lName + '<span class="text-muted"> ' + lineInfo.lStation[i].busline[j].lStartName + '→' + lineInfo.lStation[i].busline[j].lEndName + '</span><br>';
			}
		}
		point={lat:lineInfo.lStation[i].sLat +0.006531,lng:lineInfo.lStation[i].sLng + 0.012316};
		content = '<p class="mui-ellipsis text-muted">'+ lineInfo.lStation[i].sRoad + '</p>' + (content==''?'':'同站线路:<br>'+content); 
		var title = lineInfo.lStation[i].sName+(lineInfo.lStation[i].sCompass ==''?'':'<span class="text-muted"> - ' + lineInfo.lStation[i].sCompass + ' </span>')+'<p class="mui-ellipsis-2 pull-right">' + lineInfo.lStation[i].sTag + '</p>';
		map_main.openInfoWindow(new BMap.InfoWindow(content,{title:title,width:300,top:5}),new BMap.Point(point.lng, point.lat)); //开启信息窗口
	}
	
	function isIE() {
		return (!!window.ActiveXObject || "ActiveXObject" in window);
	}
	
	function postLineInfo(id,info){
		if(info==null){
			$.bigBox({
				title : "线路未选择！",
				content : "在保存之前，请先确认已经搜索过线路",
				color : "#C79121",
				timeout: 8000,
				icon : "fa fa-times fadeInLeft animated",
			});
	
		}
		if(info.lStation!=null){
			var lStation = "";
			if(info.lStation.length>0){
				lStation = info.lStation[0].sID;
				for(var i=1;i<info.lStation.length;i++){
					lStation = lStation + ',' + info.lStation[i].sID
				}
			}
			info.lStation = lStation;
		}
		$.post('//api.waitbus.com/v3/?mothed=updateLineInfo&lid=' + id + "&token=" + token,info,function(data){
			res = JSON.parse(data);
			if(res.status.code==0){
				if(id==lid){
					lineInfo = res.result;
					reloadLine();
					$.bigBox({
						title : "保存成功",
						content : "您提交的线路数据（包括基础信息和站点信息）均已提交成功",
						color : "#739E73",
						timeout: 8000,
						icon : "fa fa-check",
					});
				}
			}else{
				$.bigBox({
					title : "出现错误",
					content : res.status.msg + " [" + res.status.code + "]",
					color : "#C79121",
					timeout: 8000,
					icon : "fa fa-times fadeInLeft animated",
				});
			}
		});
	}
	
	var pagedestroy = function(){
		map_main =null;
		map_addStation = null;
		searchTime = 0;
	}
	
	Array.prototype.insert = function (index, item) {
		this.splice(index, 0, item);
	};

	function buske(i){
		staInfo = {};
		staInfo["sName"]=a.lineSites[i].sites.siteName.replace(/·/,"");
		if(a.lineSites[i].sites.inRoad!=undefined){
			staInfo['sRoad']= a.lineSites[i].sites.inRoad;
		}else{
			staInfo['sRoad']='';
		}
		if(a.lineSites[i].sites.szfx!=undefined){
			staInfo['sRoad']+=  a.lineSites[i].sites.szfx;
		}
		if(a.lineSites[i].sites.lbfx!=undefined){
			staInfo['sRoad']+=  a.lineSites[i].sites.lbfx;
		}
		if(a.lineSites[i].sites.road!=undefined){
			staInfo['sRoad']+= ", " + a.lineSites[i].sites.road
		}
		if(a.lineSites[i].sites.tag!=undefined){
			var tempCompass =a.lineSites[i].sites.tag;
			tempCompass=tempCompass.split("-");
			if(tempCompass.length==2){
				staInfo['sCompass'] = tempCompass[1].trim();
			}else{
				staInfo['sCompass']= '';
			}
		}else{
			staInfo['sCompass']= '';
		}
		staInfo['sLng']=a.lineSites[i].sites.lng - 0.012316;
		staInfo['sLat']=a.lineSites[i].sites.lat - 0.006531;
		var pinyin = pinyinUtil.getPinyin(staInfo["sName"], ' ', false, false);;
		var szm = '';
		var arrpinyin = pinyin.split(' ');
		for(var j=0;j<arrpinyin.length;j++){
			if(arrpinyin[j].length>0){
				szm+=arrpinyin[j][0];
			}
		}
		pinyin=pinyin.replace(/\s+/g, "");
		staInfo['sPinyin']=pinyin;
		staInfo['sSzm']=szm;
		console.log(pinyin);
		var allline = '';
		for(j=0;j<a.lineSites[0].sites.hcList.length;j++){
			try{
				allline+='|' + a.lineSites[i].sites.hcList[j].lineName
			}catch(err){}
		}
		console.log(allline);
		return staInfo;
	}
	function uploadStation(){
		$.post('//api.waitbus.com/v3/?mothed=createNewStation' + "&token=" + token,staInfo,function(data){res = JSON.parse(data);if(res.status.code==0){lineInfo.lStation.insert(lineInfo.lStation.length,res.result[0]);reloadLine();}});
	}
	function get84keInfo(){
		$.getJSON("//api.waitbus.com/v3/?mothed=get84kejson&iid=" + lineInfo.l84keID + "&token=" + token,function(data){
			if(data.result){
				a = data.result;
				var startend = (a.lineSites[0].sites.siteName.replace(/·/,"") + ' - '+ a.lineSites[a.lineSites.length-1].sites.siteName.replace(/·/,""))
				if(startend ==lineInfo.lStartName  + ' - '+ lineInfo.lEndName){
					for(var i=0;i<a.lineSites.length;i++){
						buske(i);
						uploadStation(false);
						sleep(200);
					}
					reloadLine();
				}else{
					console.log (startend + '起终点不同，暂未自动完成');	
				}
			}
		});	
	} 
	function sleep(numberMillis) {
		var now = new Date();
		var exitTime = now.getTime() + numberMillis;
		while (true) {
			now = new Date();
			if (now.getTime() > exitTime)
				return;
		}
	}
	$(window).resize();
	var staInfo={};
	var a ={};
</script>




